package exec;

import java.io.IOException;
import java.io.InputStreamReader;
import java.io.LineNumberReader;
import java.util.Date;

/**
 * @Title: Create By MyEclipse 6.0
 * @Package: exec.Test1.java
 * 
 * @author: marion
 * @Email: majinding888@163.com
 * @date: 2012-11-8 下午01:35:42
 * 
 * @memo:
 * 
 */

public class Test1 implements Runnable {

	/**
	 * @param args
	 * @throws Exception
	 */
	public static void main(String[] args) throws Exception {
		long time1 = System.currentTimeMillis();
		// String cmd="E://softWare//Fetion//Fetion2012//Fetion//Fetion.exe";
		String cmd = "E://softWare//Thunder//vipThunder//Program//Thunder.exe";
		// String cmd = "getmac";
		// for (int i = 0; i < 5; i++) {
		// runExe(cmd);
		// Thread.sleep(60000);
		// }
		int hours = new Date().getHours();
		// System.out.println(new Date().getHours());
		while (hours <= 16) {
			System.out.println("开始跑动="+hours +":"+new Date().getMinutes()+":"+new Date().getSeconds());
			runExe(cmd);
			Thread.sleep(180000);
		}

		long time2 = System.currentTimeMillis();
		System.out.println("耗时=" + (time2 - time1) / 1000);
		System.exit(10);
	}

	public static void runExe(String cmd) throws Exception {
		Runtime runtime = java.lang.Runtime.getRuntime();
		Thread t = new Thread(new execute());
		t.start();
		t.sleep(1000);
		t.stop();
		// t.destroy();
		t.interrupt();

		System.out.println("线程目前"+t.isAlive());
	}

	public static void runExe2(String cmd) throws Exception {

		try {
			Process process = Runtime.getRuntime().exec(cmd);
			InputStreamReader ir = new InputStreamReader(process
					.getInputStream());
			LineNumberReader input = new LineNumberReader(ir);
			String line;
			while ((line = input.readLine()) != null) {

				System.out.println(line);
			}
		} catch (java.io.IOException e) {
			System.err.println("IOException " + e.getMessage());

		}
	}

	public void run() {
	}
}

class execute implements Runnable {
	static String cmd = "E://softWare//Thunder//vipThunder//Program//Thunder.exe";;
	static String cmd2 = "getmac exit";;

	public execute() {

	}

	public static String getCmd() {
		return cmd;
	}

	public static void setCmd(String cmd) {
		execute.cmd = cmd;
	}

	public void run() {
		try {
			Runtime.getRuntime().exec(cmd);
			// Runtime.getRuntime().exec(cmd2);
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
